/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package geowiki.vis;

/**
 *
 * @author marctiedemann
 */
import geowiki.data.Place;
import geowiki.vis.PlaceMarker;
import java.util.List;
import processing.core.PApplet;

public class LineFromPlaces {

    PApplet p;

    public LineFromPlaces(PApplet p) {
        this.p = p;
    }

    public void drawLines(List<PlaceMarker> placesMarkers, int color, float lineDensity,float lineWidth) {

        if (placesMarkers.size() >= 2) {

            for (int i = 1; i < placesMarkers.size(); i++) {


                PlaceMarker pmone = (PlaceMarker) placesMarkers.get(i - 1);
                PlaceMarker pmtwo = (PlaceMarker) placesMarkers.get(i);


                //System.out.println("drawLine at X:"+pmone.getX());
                p.stroke(color, lineDensity);
               
                //p.stroke(255,lineDensity);

                p.line(pmone.getX(), pmone.getY(), pmtwo.getX(), pmtwo.getY());
            }

        }
    }

    public void drawJumper(List<PlaceMarker> placesMarkers, int color, float lineDensity, float lineLevel) {
    p.noFill();
        if (placesMarkers.size() >= 2) {

            for (int i = 1; i < placesMarkers.size(); i++) {


                PlaceMarker pmone = (PlaceMarker) placesMarkers.get(i - 1);
                PlaceMarker pmtwo = (PlaceMarker) placesMarkers.get(i);

                float distance = p.dist(pmone.getX(), pmone.getY(),pmtwo.getX(), pmtwo.getY());

                float curver = distance/(2*lineLevel);


                //System.out.println("drawLine at X:"+pmone.getX());
                p.stroke(color, lineDensity);
                
                //p.stroke(255,lineDensity);

                p.bezier(pmone.getX(), pmone.getY(),pmone.getX(), pmone.getY()-curver, pmtwo.getX(), pmtwo.getY()-curver,pmtwo.getX(), pmtwo.getY());
            }

        }
    }

    public void draw3DJumper(List<PlaceMarker> placesMarkers, int color, float lineDensity) {
    p.noFill();
        if (placesMarkers.size() >= 2) {

            for (int i = 1; i < placesMarkers.size(); i++) {


                PlaceMarker pmone = (PlaceMarker) placesMarkers.get(i - 1);
                PlaceMarker pmtwo = (PlaceMarker) placesMarkers.get(i);

                float distance = p.dist(pmone.getX(), pmone.getY(),pmtwo.getX(), pmtwo.getY());

                float curver = distance/2;


                //System.out.println("drawLine at X:"+pmone.getX());
                p.stroke(color, lineDensity);
                //p.stroke(255,lineDensity);

                p.bezier(pmone.getX(), pmone.getY(),0,pmone.getX(), pmone.getY(),curver, pmtwo.getX(), pmtwo.getY(),curver,pmtwo.getX(), pmtwo.getY(),0);
            }

        }
    }
}
